#include "bsl_params.h"
#include "bsl_err_internal.h"
#include "crypt_algid.h"
#include "crypt_errno.h"
#include "crypt_eal_provider.h"
#include "crypt_eal_implprovider.h"
#include "dh.h"
#include "rsa.h"

void *KAE_PkeyMgmt_DefaultNewCtx(void *provCtx, int32_t algId)
{
    (void) provCtx;
    void *pkeyCtx = NULL;
    switch (algId) {
        case CRYPT_PKEY_RSA:
            pkeyCtx = KAE_RSA_NewCtx();
            break;
        case CRYPT_PKEY_DH:
            pkeyCtx = KAE_DH_NewCtx();
            break;
    }
    if (pkeyCtx == NULL) {
        BSL_ERR_PUSH_ERROR(CRYPT_PROVIDER_NOT_SUPPORT);
        return NULL;
    }
    return pkeyCtx;
};

const CRYPT_EAL_Func kaeRsaMgmt[] = {
    {CRYPT_EAL_IMPLPKEYMGMT_NEWCTX, KAE_PkeyMgmt_DefaultNewCtx},
    {CRYPT_EAL_IMPLPKEYMGMT_SETPARAM, KAE_RSA_SetPara},
    {CRYPT_EAL_IMPLPKEYMGMT_GENKEY, KAE_RSA_GenKey},
    {CRYPT_EAL_IMPLPKEYMGMT_SETPRV, KAE_RSA_SetPrv},
    {CRYPT_EAL_IMPLPKEYMGMT_SETPUB, KAE_RSA_SetPub},
    {CRYPT_EAL_IMPLPKEYMGMT_GETPRV, KAE_RSA_GetPrv},
    {CRYPT_EAL_IMPLPKEYMGMT_GETPUB, KAE_RSA_GetPub},
    {CRYPT_EAL_IMPLPKEYMGMT_DUPCTX, KAE_RSA_DupCtx},
    {CRYPT_EAL_IMPLPKEYMGMT_CHECK, NULL},
    {CRYPT_EAL_IMPLPKEYMGMT_COMPARE, KAE_RSA_Cmp},
    {CRYPT_EAL_IMPLPKEYMGMT_CTRL, KAE_RSA_Ctrl},
    {CRYPT_EAL_IMPLPKEYMGMT_FREECTX, KAE_RSA_Free},
    CRYPT_EAL_FUNC_END,
};

const CRYPT_EAL_Func kaeDhMgmt[] = {
    {CRYPT_EAL_IMPLPKEYMGMT_NEWCTX, KAE_PkeyMgmt_DefaultNewCtx},
    {CRYPT_EAL_IMPLPKEYMGMT_SETPARAM, KAE_DH_SetPara},
    {CRYPT_EAL_IMPLPKEYMGMT_GENKEY, KAE_DH_Gen},
    {CRYPT_EAL_IMPLPKEYMGMT_SETPRV, KAE_DH_SetPrvKey},
    {CRYPT_EAL_IMPLPKEYMGMT_SETPUB, KAE_DH_SetPubKey},
    {CRYPT_EAL_IMPLPKEYMGMT_GETPRV, KAE_DH_GetPrvKey},
    {CRYPT_EAL_IMPLPKEYMGMT_GETPUB, KAE_DH_GetPubKey},
    {CRYPT_EAL_IMPLPKEYMGMT_DUPCTX, KAE_DH_DupCtx},
    {CRYPT_EAL_IMPLPKEYMGMT_CHECK, NULL},
    {CRYPT_EAL_IMPLPKEYMGMT_COMPARE, KAE_RSA_Cmp},
    {CRYPT_EAL_IMPLPKEYMGMT_CTRL, KAE_DH_Ctrl},
    {CRYPT_EAL_IMPLPKEYMGMT_FREECTX, KAE_DH_Free},
    CRYPT_EAL_FUNC_END,
};